package cn.xo68.boot.auth.server.mapper;


import cn.xo68.boot.auth.server.domain.OauthRefreshToken;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * OauthRefreshToken mybatis mapper
 * @author wuyy(16349023@qq.com)
 * @date 2018年08月26日 20:53:56
 *
 */
public interface OauthRefreshTokenMapper{


    @Select("SELECT * FROM oauth_refresh_token WHERE refresh_token = #{refreshToken}")
    @Results(value = {
            @Result(id = true, column = "refresh_token", property = "refreshToken"),
            @Result(column = "token", property = "token"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "client_id", property = "clientId"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "expire_time", property = "expireTime")
    })
    OauthRefreshToken get(@Param("refreshToken") String refreshToken);

    @Select("SELECT * FROM oauth_refresh_token WHERE refresh_token = #{refreshToken}")
    @Results(value = {
            @Result(id = true, column = "refresh_token", property = "refreshToken"),
            @Result(column = "token", property = "token"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "client_id", property = "clientId"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "expire_time", property = "expireTime")
    })
    OauthRefreshToken find(@Param("refreshToken") String refreshToken);

    @Select("SELECT * FROM oauth_refresh_token")
    @Results(value = {
            @Result(id = true, column = "refresh_token", property = "refreshToken"),
            @Result(column = "token", property = "token"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "client_id", property = "clientId"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "expire_time", property = "expireTime")
    })
    List<OauthRefreshToken> list();

    @Insert("insert into oauth_refresh_token (refresh_token ,token ,user_id ,client_id ,create_time ,expire_time ) values (#{refreshToken} , #{token} , #{userId} , #{clientId} , #{createTime} , #{expireTime}  )")
    @Options(useGeneratedKeys = true, keyProperty = "refreshToken")
    void insert(OauthRefreshToken oauthRefreshToken);

    @Update("update oauth_refresh_token set  token=#{token}, user_id=#{userId}, client_id=#{clientId}, create_time=#{createTime}, expire_time=#{expireTime} where refresh_token = #{refreshToken}")
    void update(OauthRefreshToken oauthRefreshToken);

    @Delete("delete FROM oauth_refresh_token WHERE refresh_token = #{refreshToken}")
    void delete(@Param("refreshToken") String refreshToken);
}